function dataConvertMenu(menu,eAct,ext,id)
{
    var reObj = Array();
    var n=0;
    for(var i=0,l=menu.length;i<l;i++)
    {
        reObj[i] = Array();
        reObj[i].type = "div";
        reObj[i].style = ["pt_menugroup"];
        reObj[i].sub = dataConvertNode(menu[i],eAct,ext,id);
    }
    return reObj;
}
function dataConvertNode(inObj,eAct,ext,id)
{
    var reObj = Array();
    var n = 0;
    for(var i in inObj)
    {
        reObj[n] = {'id':i,"type":"div","style":["pt_menuitem"],'event_act':eAct};
        if(inObj[i])
        {
            reObj[n].sub = [];
            if(inObj[i].ico){
            reObj[n].sub[0] = {'attribute':{"style":"background:transparent url("+inObj[i].ico+") no-repeat scroll right bottom"},'type':"div","style":['pt_menu_ico']};
            }else{
            reObj[n].sub[0] = {'type':'div',"style":['pt_menu_ico']};
            }
            try{
                var label = id ? inObj[i].label +"("+ i+")" : inObj[i].label;
                reObj[n].sub[1] = {"type":"div","style":["pt_menu_text"],"text":label}
            }catch(err){}
            try{
                reObj[n].sub[2] = {'type':"div","style":["pt_menu_ext"],"text":ext,'event_act':eAct+'_ext'};
            }catch(err){}
        }
        n++;
    }
    return reObj;
}
function createTab(name,src)
{
    var index = PF.length;
    PF.push(index);
    var id = FNP+index;
    var tagObj =[];//tab mark data
    tagObj.id = '_tag'+id;
    tagObj.type = "div";
    tagObj.text = name;
    tagObj.event_act = "show_frame";
    tagObj.style = ["pt_tab_btn","pt_tab_btn_active"];
    var tag = cNode(tagObj,$('tabBox'));
    var img = [];
    img.type = "img";
    img.id = '_close_tag'+id;
    img.style = ['pt_tab_close'];
    img.event_act = 'close_tab';
    img.attribute = {"src":"/images/close.png"};
    cNode(img,tag);
    var fObj = []; //active frame data
    fObj.id = id;
    fObj.type = "iframe";
    fObj.style = ["pt_active_frame"];
    var src = src ? src : "./myhome";
    fObj.attribute = {"src":src};
    cNode(fObj,$("activeDiv"));
    $('addressBarInput').value = 'http://';
    $('addressBarInput').focus();
    if(PTFF != null){
        $(FNP+PTFF).style.display = "none";
        $('_tag'+FNP+PTFF).removeClass('pt_tab_btn_active');
    }
    PTFF = index;
}
/*this is protective create node than __createNode*/
function createElementObj(objName,objType,superObj)
{
    if(Emt.isId(objName))
    {
        return false;
    }else{
        if(Emt.isObj(superObj) == false)
        {
            var superObj = $('ptalk');
        }
       return  __createNode(superObj,objType,objName);
    }
}
function createTalkBox(id,newCreate)
{
    if($(id+'_talk_box'))
    {
        var $style = $(id+'_talk_box').style;
        if($style.display == 'none')
        {
            $style.display = 'block';
        }
        return false;
    }else{
        var msgTitle = id;
        var min = {"type":"div","style":["pt_talk_box_min"],'event_act':"min_msg_box"};
        var close = {"type":"div","style":["pt_talk_box_close"],'event_act':"close_msg_box"};
        var title = {"type":"div","text":msgTitle,"style":["pt_talk_box_title"],"event_act":"move_talk_box"};
        var bChar = {"type":"img","attribute":{"src":"./images/b.png","alt":'粗体',"title":"粗体"},"event_act":"add_b_html"};
        var iChar = {"type":"img","attribute":{"src":"./images/i.png","alt":"斜体","title":"斜体"},"event_act":"add_i_html"};
        var uChar = {"type":"img","attribute":{"src":"./images/u.png","alt":"下划线","title":"下划线"},"event_act":"add_u_html"};
        var colorChar = {"type":"img","attribute":{"src":"./images/color.png","alt":"字体颜色","title":"字体颜色"},"event_act":"show_char_color_box"};
        var tChar = {"type":"img","attribute":{"src":"./images/t.png","alt":"背景颜色","title":"背景颜色"},"event_act":"show_bg_color_box"};
        var linkChar = {"type":"img","attribute":{"src":"./images/link.png","alt":"链接","title":"链接"},"event_act":"add_link_html"};
        var addImg = {"type":"img","attribute":{"src":"./images/img.gif","alt":"添加图片","title":"添加图片"},"event_act":"add_img"};
        var att = {"type":"img","attribute":{"src":"./images/att.png","alt":"附件","title":"附件"},"event_act":"add_att"};
        var charSize = {"type":"select","event_act":"char_size","style":["pt_talk_box_tool_select"],"text":"<option value=0>字体大小</option><option value=1>8 pt</option><option value=2>10 pt</option><option value=3>12 pt</option><option value=4>14 pt</option><option value=5>18 pt</option><option value=6>24 pt</option>"}
        var tool = {"type":"div","style":["pt_talk_box_tool"],"sub":[bChar,iChar,uChar,colorChar,tChar,linkChar,addImg,att,charSize]};
        if(newCreate)
        {
            var me_info = {"type":"div","text":getDate()+" Me:","style":["pt_msg_me_send"]};
        var done_btn = {"type":"pt_button","text":"确定","style":["pt_btn","pt_msg_box_btn"],"event_act":"msg_reply_done"};
        var pt_editer = {"type":"div","style":["pt_editer"],"text":"<div><p><br /></p></div>","attribute":{"contenteditable":"true","editabledocmarker":"true"},'event_act':'editer_focus'};
        var talkmsg = {"type":"div","style":["pt_user_msg_input"],'sub':[me_info,pt_editer,done_btn]};
        }else{
            var msgBoxReplyBtn = {"type":"pt_button","text":"回复","style":["pt_btn","pt_msg_box_btn"],'event_act':"reply_msg"};
            var talkmsg = {"type":"div","style":["pt_user_msg_input"],"sub":[msgBoxReplyBtn],"text":"<div class=pt_msg_send_info>"+getDate()+"test </div><div>hi:<br />this is the other user talk msg</div>"}
        }
        var msg = {"type":"div","style":["pt_talk_box_msg"],'event_act':"input_msg","attribute":{'title':"点击回复"},"sub":[talkmsg]};
        var talkBoxData = {"id":id+"_talk_box","style":["pt_talk_box"],"type":"div","sub":[title,min,close,tool,msg]};
        var NowBox = cElement(talkBoxData,$('ptalk'));
        if(TALKBOXNUM > 0)
        {
            var left = 200 + TALKBOXNUM * 20;
            var topPos = 75 + TALKBOXNUM * 20;
            NowBox.style.cssText = "left:"+left+"px;top:"+topPos+"px";
        }
        TALKBOXNUM +=1;
        var statusBtn = {"type":"pt_button","text":msgTitle,"id":id+"_status_btn","style":["pt_btn"],"event_act":"status_talk_box_btn"}
        cElement(statusBtn,$('statusBar'));
        return NowBox;
    }
}
function createColorBox()
{
    
    var color = ['000','444','666','999','CCC','EEE','F3F3F3','FFF'];
    var b2w_tr = loopCNodeData(8,"td",color,'b2w');
    var b2w = {'type':"table","sub":[{"type":"tr","sub":b2w_tr}],"attribute":{"cellspacing":"0","cellpadding":"0"}};
    var color = ['FF0000','FF9900','FFFF00','00FF00','00FFFF','0000FF','9900FF','FF00FF'];
    var color_shade = loopCNodeData(8,"td",color,'shade');
    var color_shade_table = {"type":"table","sub":[{"type":"tr","sub":color_shade}],"attribute":{"cellspacing":"0","cellpadding":"0"},"style":["pt_color_center_table"]};
    var color_box_sub = [];
    var color = [];
    color.append(['F4CCCC','FCE5CD','FFF2CC','D9EAD3','D0E0E3','CFE2F3','D9D2E9','EAD1DC']);
    color.append(['EA9999','F9CB9C','FFE599','B6D7AB','A2C4C9','9FC5E8','B4A7D6','D5A6BD']);
    color.append(['E06666','F6B26B','FFD966','93C47D','76A5AF','6FA8DC','8E7CC3','C27BA0']);
    color.append(['C00','E69138','F1C232','6AA84F','45818E','3D85C6','674EA7','A64D79']);
    color.append(['900','B45F06','BF9000','38761D','134F5C','0B5394','351C75','741B47']);
    color.append(['600','783F04','7F6000','274E13','0C343D','073763','20124D','4C1130']);
    for(var i=0;i<6;i++)
    {
        var box_td = loopCNodeData(8,"td",color[i],'table'+i);
        var box_tr = {"type":"tr","sub":box_td};
        color_box_sub.append(box_tr);
    }
    var color_box = {"type":"table","sub":color_box_sub,"attribute":{"cellspacing":"0","cellpadding":"0"}};
    var box = {"type":"div","event_act":"chg_color","style":["pt_color_box"],"id":"pt_color_box","sub":[b2w,color_shade_table,color_box]};
    var color = cElement(box,$('ptalk'));
    return color;
}
function createInput(obj)
{
       var userMsgObj = {"type":"div","event_act":"input_msg_option","style":["pt_user_msg_input"],"attribute":{"spellcheck":"false"}};
    var userMsgInput = cElement(userMsgObj,msgBox);
    var msgBoxReplyObj = {"type":"pt_button","text":"回复","id":"msg_box_reply","style":["pt_btn"]};
    cElement(msgBoxReplyObj,userMsgInput);
    
}
function createEdit(obj){
    obj.contentEditable = true;
    obj.style.cssText = "height:auto";
    obj.innerHTML = "<div><p></p></div>";
    obj.focus();
    var s = ptSelection();
    obj.selectionStart = 8;
}
function createParagraph(html)
{
    var p = document.createElement('p');
    p.innerHTML = html;
    return p;
}
function createBtn(text)
{
    var baseObj = document.createElement('div');
    var upObj = document.createElement('div');
    var content = document.createElement('div');
    content.innerHTML = text;
    upObj.innerHTML = ' ';
    content.setAttribute("class",'pt_btn_text');
    upObj.setAttribute("class", 'pt_btn_shadow');
    baseObj.setAttribute("class",'pt_btn_base','pt_btn_border');
    baseObj.appendChild(upObj);
    baseObj.appendChild(content);
    return baseObj;
}
function createMenu(eObj,menu,data,eAct,ext,id)
{
    if(isset(eObj.id) == false)
    {
        var eObj= $(__LoopFindId(eObj));
    }
    var pos = getObjPos(eObj);
    var pLeft = pos.x;
    var pTop = pos.y+pos.h-5;
    var mMenu = createElementObj(menu,'div');
    mMenu.style.cssText = "left:" +pLeft+ "px;top:"+pTop+"px;visibility: visible";
    var MenuObj = dataConvertMenu(data,eAct,ext,id);
    for(var j in MenuObj) cElement(MenuObj[j], mMenu);
}
function createAddLinkBox(eobj,tagtext)
{
    if(tagtext == false)
    {
        tagtext = 'Enter Link Text';
        var text = {"type":"input","id":"pt_add_link_text","attribute":{"type":"text","value":tagtext,"title":"Link Text"},"event_act":"link_text"};
    }else{
        var text = {"type":"input","attribute":{"type":"text","value":tagtext,"title":"Link Text","readonly":true},"event_act":"link_text"};
    }
    var address = {"type":"input","id":"pt_add_link_address","attribute":{"type":"text","value":"Enter URL","title":"URL"},"event_act":"link_input"};
    var cancel = {"type":"pt_button","text":"取消","style":["pt_btn"],"event_act":"link_cancel"};
    var submit = {"type":"pt_button","text":"确定","style":["pt_btn"],'event_act':"link_enter"};
    var box ={"type":"div","sub":[address,cancel,text,submit],"style":['pt_com_box']};
    var boxObj = cElement(box,eobj.parentNode);
//    USER_LINK_ADD = null;
  //  USER_LINK_TEXT = null;
    EA(boxObj,true);
//    boxObj.style.cssText = "left:"+pLeft+"px;top:"+pTop+"px;";
}
function createUpFile(obj)
{
    var file = {"type":"input","attribute":{"type":"file"}};
    var submit = {"type":"input","attribute":{"type":"submit","value":"发送"}};
    var cancel = {"type":"pt_button","text":"取消","style":['pt_btn'],'event_act':"cancel_upfile"};
    var form = {"type":"form",'sub':[file,submit,cancel],"attribute":{"method":"post","enctype":"multipart/form-data"}}
    cElement(form,obj);
}

